package com.zc.demo;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpServletMapping;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public Boolean login(String userName, String password, HttpSession session){
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)){
            return false;//长度为0,
        }

        if("admi".equals(userName) && "password".equals(password)){
            //由于要让第二个要获取用户信息，所以得先设置seesion
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }

    @RequestMapping("/getLoginUser")
    public String getUserName(HttpSession session){
        if(session.getAttribute("userName") != null){
            return (String)session.getAttribute("userName");
        }
        return "";
    }
}
